package net.lab1024.smartadmin.module.business.scenicSpot.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.module.business.scenicSpot.dao.ScenicSpotDao;
import net.lab1024.smartadmin.module.business.scenicSpot.domain.dto.ScenicSpotAddDTO;
import net.lab1024.smartadmin.module.business.scenicSpot.domain.dto.ScenicSpotUpdateDTO;
import net.lab1024.smartadmin.module.business.scenicSpot.domain.dto.ScenicSpotQueryDTO;
import net.lab1024.smartadmin.module.business.scenicSpot.domain.entity.ScenicSpotEntity;
import net.lab1024.smartadmin.module.business.scenicSpot.domain.vo.ScenicSpotVO;
import net.lab1024.smartadmin.module.business.scenicSpot.domain.vo.ScenicSpotExcelVO;
import net.lab1024.smartadmin.util.SmartPageUtil;
import net.lab1024.smartadmin.util.SmartBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * [  ]
 *
 * @author wldd
 * @version 1.0
 * @company 景区
 * @copyright (c)  景区Inc. All rights reserved.
 * @date 2020-12-26 14:25:23
 * @since JDK1.8
 */
@Service
public class ScenicSpotService {

    @Autowired
    private ScenicSpotDao scenicSpotDao;

    /**
     * 根据id查询
     */
    public ScenicSpotEntity getById(Long id){
        return  scenicSpotDao.selectById(id);
    }

    /**
     * 分页查询
     * @author wldd
     * @date 2020-12-26 14:25:23
     */
    public ResponseDTO<PageResultDTO<ScenicSpotVO>> queryByPage(ScenicSpotQueryDTO queryDTO) {
        Page page = SmartPageUtil.convert2QueryPage(queryDTO);
        IPage<ScenicSpotVO> voList = scenicSpotDao.queryByPage(page, queryDTO);
        PageResultDTO<ScenicSpotVO> pageResultDTO = SmartPageUtil.convert2PageResult(voList);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * 添加
     * @author wldd
     * @date 2020-12-26 14:25:23
     */
    public ResponseDTO<String> add(ScenicSpotAddDTO addDTO) {
        ScenicSpotEntity entity = SmartBeanUtil.copy(addDTO, ScenicSpotEntity.class);
        scenicSpotDao.insert(entity);
        return ResponseDTO.succ();
    }

    /**
     * 编辑
     * @author wldd
     * @date 2020-12-26 14:25:23
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(ScenicSpotUpdateDTO updateDTO) {
        ScenicSpotEntity entity = SmartBeanUtil.copy(updateDTO, ScenicSpotEntity.class);
        scenicSpotDao.updateById(entity);
        return ResponseDTO.succ();
    }

    /**
     * 删除
     * @author wldd
     * @date 2020-12-26 14:25:23
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> deleteByIds(List<Long> idList) {
        scenicSpotDao.deleteByIdList(idList);
        return ResponseDTO.succ();
    }

    /**
     * 查询全部导出对象
     * @author wldd
     * @date 2020-12-26 14:25:23
     */
    public List<ScenicSpotExcelVO> queryAllExportData(ScenicSpotQueryDTO queryDTO) {
        return scenicSpotDao.queryAllExportData( queryDTO);
    }

    /**
     * 批量查询导出对象
     * @author wldd
     * @date 2020-12-26 14:25:23
     */
    public List<ScenicSpotExcelVO> queryBatchExportData(List<Long> idList) {
        return scenicSpotDao.queryBatchExportData(idList);
    }
}
